<%@page import="beans.Goods"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
<link href="<%=path%>/admin/css/haiersoft.css" rel="stylesheet"
	type="text/css" />
<link href="<%=path%>/admin/css/print.css" rel="stylesheet"
	type="text/css" media="print" />
<script src="<%=path%>/admin/js/jquery-1.10.1.min.js"></script>
<script src="<%=path%>/admin/js/side.js" type="text/javascript"></script>
<script src="<%=path%>/admin/js/function.js" type="text/javascript"></script>
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script>
<![endif]-->
<script type="text/javascript">
$(function() {
	var i = 1;
	$('tbody>tr').each(function(){
			this.onmouseover = function() {
				this.style.backgroundColor = '#E0FFFF';
			};
		if (i % 2 == 0){
			this.onmouseout = function() {
				this.style.backgroundColor = '#edf5ff';
			};
			this.style.backgroundColor = '#edf5ff';
		}else{
			this.onmouseout = function() {
				this.style.backgroundColor = '#fff';
			};
		}
		i++;
	});
});
</script>
</head>

<body>
	<!-- MainForm -->
	<div id="MainForm">
		<div class="form_boxA">
			<form id="searchForm" action="<%=path %>/GoodServlet" method="post">
				<table style="width: 500px">
					<tr id="search">
						<td><label for="name">商品名称:</label></td>
						<td><input id="name" name="name" value="${name }"
							placeholder="请输入商品名称！" type="text" /></td>
						<td><input id="page" name="page" placeholder="Text"
							type="hidden" value="1" /> <input id="id" name="id" placeholder="Text"
							type="hidden" value="${id }" /> <input type="submit" value="搜索" /></td>
						<td>
							<input type="button" onclick="location='<%=path %>/GoodsOperationServlet?operation=add&sid=${id }'" value="添加商品" />
						</td>
					</tr>
				</table>
			</form>
			<h2>商品列表</h2>
			<table>
			<thead>
				<tr>
					<th>编号</th>
					<th>商品名称</th>
					<th>价格</th>
					<th>种类</th>
					<th>库存</th>
					<th>销量</th>
					<th>描述</th>
					<th>是否销售</th>
					<th>商铺号</th>
					<th>操作</th>
				</tr>
				</thead>
				<tbody>
				<%
					@SuppressWarnings("unchecked")
					List<Goods> goods = (List<Goods>) request.getAttribute("goods");
					for (Goods good : goods) {
				%>
				<tr>
					<td><%=good.getId()%></td>
					<td><%=good.getName()%></td>
					<td><%=good.getPrice()%></td>
					<td><%=good.getClassify()%></td>
					<td><%=good.getStock()%></td>
					<td><%=good.getSales()%></td>
					<td><%=good.getGoodDescribe()%></td>
					<td><%=good.getStatus()%></td>
					<td><%=good.getShop().getId() %></td>
					<td><a href="<%=path%>/GoodsOperationServlet?operation=alt&id=<%=good.getId()%>&sid=<%=good.getShop().getId()%>">修改</a> | <a href="javascript:void(0)"
						onclick="deleteTr(this,'GoodsOperationServlet','<%=path%>')">删除</a></td>
				</tr>
				<%
					}
				%>
				</tbody>
			</table>
			<script type="text/javascript">
				function toPage(pageNum) {
					var page = document.getElementById('page');
					var searchForm = document.getElementById('searchForm');
					var count = ${count};
					var maxPage = parseInt(count / 15) + 1;
					if (pageNum < 1)
						page.value = 1;
					else if (pageNum > maxPage)
						page.value = maxPage;
					else
						page.value = parseInt(pageNum);
					searchForm.submit();
				}
			</script>
			<!-- PageNum -->
			<ul id="PageNum">
				<li><a href="javascript:toPage(1)">首页</a></li>
				<li><a href="javascript:toPage(${page }-1)">上一页</a></li>
				<li><a href="javascript:void(0)">${page }</a></li>
				<li><a href="javascript:toPage(${page }+1)">下一页</a></li>
				<li><a href="javascript:toPage(${count/15+1 })">尾页</a></li>
			</ul>
			<!-- /PageNum -->
			<p class="msg">共找到${count }条记录，当前显示从第${(page-1)*15+1 }条至第${page*15>count?count:page*15 }条</p>
		</div>
	</div>
	<!-- /MainForm -->

</body>
</html>